package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class CustomerContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CustomerContainer  //Class which creates the container, which contains customers
{
    // instance variables - replace the example below with your own
    private ArrayList<Customer> customerList;
    private static CustomerContainer instance;

    /**
     * Constructor for objects of class CustomerContainer
     */
    private CustomerContainer()
    {
        customerList = new ArrayList<Customer>();
    }
    
    public static CustomerContainer getInstance() //makes use of singleton, so we only can create one list
    {
        if(instance == null)
        {
            instance = new CustomerContainer();
        }
        
        return instance;
    }
    
    public void addCustomer(Customer newCustomer)  // adds customer to the list
    {
        customerList.add(newCustomer);
    }
    
    public Customer findCustomer(String name, String code)  //finds a customer in the list and returns the customer
    {
        int index = 0;
        boolean found = false;
        Customer tempCust = null;
        while(!found && index < customerList.size())
        {
            if(customerList.get(index).getName().equals(name) && customerList.get(index).getCode().equals(code))
            {
                found = true;
                tempCust = customerList.get(index);
                customerList.get(index).printAll();
            }
            else
            {
                index++;
            }
        }
        if(!found)
        {
            System.out.println("Customer not found");
        }
        return tempCust;
    }
}
